package zd.vrp.ais;

import java.util.ArrayList;
import java.util.List;

import zd.vrp.utils.SolutionUtils;


/**
 * this class is used to calculate density information for each solution in population
 * @author zd
 *
 */
public class Density {
	private List<List> population;
	
	private List densityList = new ArrayList();
	private double totalDensity = 0.0;
	private double averageDensity;
	
	public Density(List population){
		this.population = population;
		calDensity();
	}
	
	private void calDensity(){
		densityList.clear();
		totalDensity = 0.0;
		
		for(int i=0;i<population.size();i++){
			List currentSolution = population.get(i);
			double currentDenstiy = 0.0;
			
			for(int j=0;j<population.size();j++){
				currentDenstiy = currentDenstiy + SolutionUtils.distanceBetween2SolutionByObjective(currentSolution, population.get(j));
			}
			
			totalDensity += currentDenstiy;
			densityList.add(currentDenstiy);
		}
	}
	
	public double getTotal(){
		return totalDensity;
	}
	
	public double getAverage(){
		return totalDensity/population.size();
	}
	
}
